package ArithmeticSummary;

import com.sun.org.apache.bcel.internal.generic.RETURN;

import java.sql.SQLOutput;

public class BubbleSort {
//    public static void main(String[] args) {
//        int[] arr = new int[]{1, 6, 4, 8, 2, 9};
//        LtsSort(arr);
//        Print(arr);
//        System.out.print("{");
//        for (int i = 0; i < arr.length; i++) {
//             System.out.print(i == arr.length -1 ? arr[i] + "}" : arr[i]+",");
//        }

//        System.out.print("{");
//        for (int i = 0; i < arr.length; i++) {
//            if (i == arr.length - 1) {
//                System.out.print(arr[i]);
//                System.out.print("}");
//                return;
//            }
//            System.out.print(arr[i] + ",");
//        }
//    }

    //从大到小
    public static void LtsSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] < arr[j + 1]) {      //从大到小，如果从小到大排，改为">";
                    swap(arr,j,j+1);
                }
            }
        }
    }

    //从小到大
    public static void StlSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - j - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    swap(arr,j,j+1);
                }
                //int temp=arr[j];
                //arr[j]=arr[j]>arr[j+1]?arr[j+1]:arr[j];
                //arr[j+1]=arr[j]>arr[j+1]?temp:arr[j+1];
            }
        }
    }

    //打印
    public static void Print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }
    }
    //交换
    public static void swap(int[] arr,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}


